package goleetcode

import "math"

func maxHeightOfTriangle(red int, blue int) int {
	return max(height(red, blue), height(blue, red))
}

func height(x, y int) int {
	odd := 2 * int(math.Sqrt(float64(x))) - 1
	even := 2 * int((-1 + math.Sqrt(1 + 4 * float64(y))) / 2)
	return min(odd, even) + 1
}